package cn.sangedon.review.analysis.strategy;

import cn.sangedon.review.analysis.constant.StrategyEnum;
import cn.sangedon.review.analysis.service.StockStrategyResultService;
import cn.sangedon.review.analysis.strategy.specific.AbstractScheduleTradeStrategy;
import cn.sangedon.review.analysis.strategy.specific.FallShrinkRedStrategy;
import cn.sangedon.review.analysis.strategy.specific.FiveHalfVolStrategy;
import cn.sangedon.review.analysis.strategy.specific.TenAverageVolStrategy;
import cn.sangedon.review.common.domain.analysis.StockStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

public interface IStrategyFactory {
    IStrategy createStrategy(StockStrategy stockStrategy);

    @Slf4j
    @Component
    class StockStrategyFactory implements IStrategyFactory {
        @Autowired
        private StockStrategyResultService stockStrategyResultService;

        @Autowired
        private TenAverageVolStrategy tenAverageVolStrategy;

        @Autowired
        private FiveHalfVolStrategy fiveHalfVolStrategy;

        @Autowired
        private FallShrinkRedStrategy fallShrinkRedStrategy;

        @Override
        public AbstractScheduleTradeStrategy createStrategy(StockStrategy stockStrategy) {
            if (stockStrategy == null) {
                log.info("选股策略为空");
                return null;
            }

            AbstractScheduleTradeStrategy strategy = null;
            if (stockStrategy.getStrategyName().equals(StrategyEnum.FIVE_DAY_HALF.getName())) {
                strategy = fiveHalfVolStrategy;
            } else if (stockStrategy.getStrategyName().equals(StrategyEnum.TEN_DAY_AVE.getName())) {
                strategy = tenAverageVolStrategy;
            } else if (stockStrategy.getStrategyName().equals(StrategyEnum.FALL_SHRINK_RED.getName())) {
                strategy = fallShrinkRedStrategy;
            }

            if (strategy != null) {
                strategy.setStockStrategy(stockStrategy);
            }

            return strategy;
        }
    }
}
